<?php
/**
 * Created by Silent Night.
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/9/28
 * Time: 9:19
 */

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;

class User extends Controller
{
    private $_model;
    private $title_field = [

    ];
    public $pagesize = 10;

    public function _initialize()
    {
        (new \app\admin\behavior\CheckPermissions())->run();//增加权限控制,使用方式一
        //$param=array();
        //\think\Hook::listen('aop_permissions',$param);//增加权限空时，使用标签钩子方式
        $this->_model = new \app\admin\model\User();
        $this->assign('LoginUserInfo', $this->LoginUserInfo);
        //获取当前用户的权限信息
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }

    public function phpinfo()
    {
       echo  captcha_src();
    }

    /**
     * 列表页
     * @return mixed
     */
    public function index()
    {

        return $this->fetch('index');
    }

    public function researchUser()
    {
        $ser_key = trim(input("request.ser_key"));//auth
        $ser_val = trim(input("request.ser_val"));//auth
        $group = trim(input("request.group"));//auth
        $firstDep = trim(input("request.firstDep"));//auth
        $secondDep = trim(input("request.secondDep"));//auth

        if ($ser_key && $ser_val) {
            $where[$ser_key] = array('like', '%' . $ser_val . '%');
        }
        if (!empty($group)) {
            $where['group'] = $group;
        }
        if (!empty($firstDep)) {
            $where['first_depid'] = $firstDep;
        }

        if (!empty($secondDep)) {
            $where['depid'] = $secondDep;
        }

        $lists = $this->_model->getDataForWheres($where, 'id,uname,nickname');

        $return = array('err' => 0, 'msg' => '获取数据成功', 'data' => $lists);
        return json($return);
    }

    public function lists()
    {
        $ser_key = trim(input("request.ser_key"));//auth
        $ser_val = trim(input("request.ser_val"));//auth
        $group = trim(input("request.group"));//auth
        $firstDep = trim(input("request.firstDep"));//auth
        $page = trim(input("request.page"));//auth
        if(empty($page))
        {
            $page=1;
        }
        $pagesize= 10;
        $where = '';
        if ($ser_key && $ser_val) {
            $where .= ' and a.' . $ser_key . ' like "%' . $ser_val . '%" ';
        }

        $where .= ' and a.is_delete = "0" ';

        //查询分组
        $isSupperManager = isSupperManagerForSession();
        $groupList = array();
        if ($isSupperManager == 0)//不是超级管理员
        {
            $groupList = getMyManagerGroup();
        } else {
            $groupList = getAllSystemGroup();
        }

        $depid = $this->LoginUserInfo['UserInfo']['first_depid'];

        if (isManagerForSession() == 0) {//如果不是管理员 就查询自己部门的
            $where .= ' and a.first_depid = "' . $depid . '" ';
        } else {
            if ($firstDep) {
                $where .= ' and a.first_depid = "' . $firstDep . '" ';
            }
        }
        $this->assign('groupList', $groupList);
        $this->assign('groupList_mk', $groupList);
        $depModel = new \app\admin\model\Dep();
        $FirstDepList = $depModel->getDataForWheres(array(
            'father' => 0
        ));//查询一级部门
        $tmpFirstDepList = array();
        foreach ($FirstDepList as $k => $v) {
            $tmpFirstDepList[$v['id']] = $v;
        }
        $this->assign('FirstDepList', $tmpFirstDepList);


        if (!empty($group)) {
            $where .= ' and b.gid = "' . $group . '" ';
        } else {
            $myManagerGroupId = array();
            foreach ($groupList as $k => $v) {
                $myManagerGroupId[] = $v['id'];
            }
            $where .= ' and b.gid in (' . implode(",", $myManagerGroupId) . ') ';
        }

        $baseModel = new \app\admin\model\BaseModel();
        $sql = "select DISTINCT a.* from t_user as a,t_user_group as b where a.id = b.uid " . $where." order by ctime desc";
        $lists = $baseModel->listsForSQL($sql,$pagesize,$page);
        $this->assign('lists', $lists);
        $this->assign('request', input("request."));
        return view('lists');
    }

    public function userAddGroup()
    {
        $sys_opt = trim(input("request.sys_opt"));//auth
        $uid = trim(input("request.uid"));//auth
        //获取所有角色
        $isSupperManager = isSupperManagerForSession();
        $groupList = array();
        if ($isSupperManager == 0)//不是超级管理员
        {
            $groupList = getMyManagerGroup();
        } else {
            $groupList = getAllSystemGroup();
        }


        if ($sys_opt) {
            $gid = trim(input("request.gid"));//auth
            if (empty($uid)) {
                $return = ['err' => 3, 'msg' => '参数错误'];
                return json($return);
            }
            if (empty($gid)) {
                $return = ['err' => 3, 'msg' => '请选择角色组'];
                return json($return);
            }
            $w = array(
                'gid' => $gid,
                'uid' => $uid
            );

            $model = new \app\admin\model\UserGroup();
            $info = $model->getDataForWhere($w);
            if (!empty($info)) {
                $return = ['err' => 3, 'msg' => '操作失败,该用户已经是该角色了'];
                return json($return);
            }

            $myManagerGroupId = array();
            foreach ($groupList as $k => $v) {
                $myManagerGroupId[] = $v['id'];
            }
            if(!in_array($gid,$myManagerGroupId))
            {
                $return = ['err' => 3, 'msg' => '操作失败,您不无权配置该角色组'];
                return json($return);
            }

            $data = $w;
            $data['ctime'] = date("Y-m-d H:i:s");
            $res = $model->add($data);

            if ($res > 0) {
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        $this->assign('groupList', $groupList);
        //获取当前有的角色
        $baseModel = new \app\admin\model\BaseModel();
        $sql = "select a.*,b.ctime as op_ctime from t_group as a,t_user_group as b where  b.uid='" . $uid . "' and a.id = b.gid";
        $lists = $baseModel->listsForSQL($sql);
        $this->assign('lists', $lists);
        $this->assign('uid', $uid);
        $this->assign('request', input("request."));
        return view('userAddGroup');
    }

    public function moneyDetail()
    {
        $pid = trim(input("request.pid"));//auth
        $ser_starttime = trim(input("request.ser_starttime"));//auth
        $ser_endtime = trim(input("request.ser_endtime"));//auth
        $ser_ty = trim(input("request.ser_ty"));//auth

        $w = array();
        if (!empty($ser_starttime) && !empty($ser_endtime)) {
            $w['ctime'] = array('between', strtotime($ser_starttime) . "," . strtotime($ser_endtime));
        }
        if ($ser_ty == '0' || $ser_ty == '1') {
            $w['ty'] = $ser_ty;
        }
        $UserMedalModel = new \app\admin\model\MoneyDetail();
        $w['uid'] = $pid;
        $lists = $UserMedalModel->lists($w, $this->pagesize);
        $lists['data'] = changeUidToUserinfoForLists($lists['data'], 'uid');

        $this->assign('lists', $lists);
        $this->assign('pid', $pid);
        $this->assign('request', input("request."));
        return view('moneyDetail');

    }

    public function delUserGroupData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        $uid = trim(input("request.uid"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $model = new \app\admin\model\UserGroup();
        $res = $model->delData(
            array('gid' => $id,'uid'=>$uid)
        );
        if ($res || ($res === 0)) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
    }


    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $userInfo = $this->_model->getID($id);
        $res = $this->_model->updateDataForWhere(
            array('is_delete' => '1'),//0正常、1禁用
            array('id' => $id)
        );
        if ($res || ($res === 0)) {
            //操作日志记录
            $action = "删除用户[" . $userInfo['uname'] . "][" . $userInfo['nickname'] . "][id:" + $id + "]";

            $this->recordSystemLog([
                'user' => $this->LoginUserInfo['UserInfo']['id'],
                'time' => date("Y-m-d H:i:s"),
                'action' => $action,
                'type' => 4,
            ]);
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }


    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delUserresumeData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Userresume();
        $res = $model->delData(array('id' => $id));
        if ($res) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
    }


    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delTaskData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Task();
        $res = $model->delData(array('id' => $id));
        if ($res) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
    }


    public function delMsgData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Msg();
        $res = $model->delData(array('id' => $id));
        if ($res) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
    }

    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delUserScoreData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $model = new \app\admin\model\Userscore();

        $res = $model->delData(array('id' => $id));

        if ($res) {


            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }

    public function recordSystemLog($arr)
    {
        $model = new \app\admin\model\Log();
        $model->add($arr);
    }


    public function wxopenid()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        $userInfo = $this->_model->getID($id);
        if (empty($id)) {

            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $userInfo = $this->_model->getID($id);
        $res = $this->_model->updateDataForWhere(
            array('openid' => ''),//0正常、1禁用
            array('id' => $id)
        );
        if ($res || ($res === 0)) {

            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }


    /**
     * 启用
     * @return mixed
     */
    public function qyData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        $userInfo = $this->_model->getID($id);
        if (empty($id)) {

            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $userInfo = $this->_model->getID($id);
        $res = $this->_model->updateDataForWhere(
            array('stat' => 0),//0正常、1禁用
            array('id' => $id)
        );
        if ($res || ($res === 0)) {
            //操作日志记录
            //$userInfo =$this->_model->getID($id);
            $action = "启用用户[" . $userInfo['uname'] . "][" . $userInfo['nickname'] . "][id:" + $id + "]";

            $this->recordSystemLog([
                'user' => $this->LoginUserInfo['UserInfo']['id'],
                'time' => date("Y-m-d H:i:s"),
                'action' => $action,
                'type' => 4,
            ]);
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }


    /**
     * 禁用
     * @return mixed
     */
    public function jyData()
    {
        $return = [];
        $id = trim(input("request.id"));//auth

        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $userInfo = $this->_model->getID($id);
        $res = $this->_model->updateDataForWhere(
            array('stat' => 1),//0正常、1禁用
            array('id' => $id)
        );

        if ($res || ($res === 0)) {
            //操作日志记录
            //$userInfo =$this->_model->getID($id);
            $action = "禁用用户[" . $userInfo['uname'] . "][" . $userInfo['nickname'] . "][id:" . $id . "]";

            $this->recordSystemLog([
                'user' => $this->LoginUserInfo['UserInfo']['id'],
                'time' => date("Y-m-d H:i:s"),
                'action' => $action,
                'type' => 4,
            ]);
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }


    }


    public function selectDeptChange()
    {
        $return = [];
        $id = trim(input("request.id"));//auth
        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }
        $model = new \app\admin\model\Dep();
        $res = $model->getDataForWheres(
            array('father' => $id)
        );


        $return = ['err' => 0, 'msg' => '操作成功', 'data' => $res];
        return json($return);


    }

    public function addUserresumeData()
    {
        $sys_opt = trim(input("request.sys_opt"));//auth
        $pid = trim(input("request.pid"));//auth
        if ($sys_opt) {
            $stime = trim(input("request.stime"));//auth
            $etime = trim(input("request.etime"));//auth
            $conts = trim(input("request.conts"));//auth


            if (empty($stime)) {

                $return = ['err' => 3, 'msg' => '开始时间不能够为空'];
                return json($return);
            }

            if (empty($etime)) {

                $return = ['err' => 3, 'msg' => '结束时间不能够为空'];
                return json($return);
            }
            if (empty($conts)) {

                $return = ['err' => 3, 'msg' => '履历内容不能够为空'];
                return json($return);
            }


            $insertData = array(
                'stime' => $stime,
                'etime' => $etime,
                'conts' => $conts,
                'uid' => $pid,

            );
            $model = new \app\admin\model\Userresume();
            $res = $model->add($insertData);

            if ($res) {

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "添加履历";
        $this->assign('title', $title);
        $this->assign('pid', $pid);

        return view('addUserresumeData');

    }


    public function editUserresumeData()
    {

        $id = trim(input("request.id"));//auth
        $pid = trim(input("request.pid"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        $model = new \app\admin\model\Userresume();
        //查询用户
        $info = $model->getDataForWhere(array('id' => $id));

        if ($sys_opt) {
            $stime = trim(input("request.stime"));//auth
            $etime = trim(input("request.etime"));//auth
            $conts = trim(input("request.conts"));//auth


            if (empty($stime)) {

                $return = ['err' => 3, 'msg' => '开始时间不能够为空'];
                return json($return);
            }

            if (empty($etime)) {

                $return = ['err' => 3, 'msg' => '结束时间不能够为空'];
                return json($return);
            }
            if (empty($conts)) {

                $return = ['err' => 3, 'msg' => '履历内容不能够为空'];
                return json($return);
            }

            $w = array(
                'id' => $id
            );
            $update = array(
                'stime' => $stime,
                'etime' => $etime,
                'conts' => $conts,
                'uid' => $pid,
            );
            $res = $model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        $this->assign('info', $info);

        //设置全局信息
        $title = "编辑履历";
        $this->assign('title', $title);
        $this->assign('id', $id);
        $this->assign('pid', $pid);
        return view('editUserresumeData');

    }


    public function addPartymoneyData()
    {


        $pid = trim(input("request.pid"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        $userinfo = $this->_model->getID($pid);
        $model = new \app\admin\model\Partymoney();


        if ($sys_opt) {

            $stime = trim(input("request.stime"));//auth
            $money = trim(input("request.money"));//auth

            if (empty($stime)) {

                $return = ['err' => 3, 'msg' => '缴费时间不能够为空'];
                return json($return);
            }

            if (empty($money)) {

                $return = ['err' => 3, 'msg' => '缴费金额不能够为空'];
                return json($return);
            }

            $temp = explode("-", $stime);
            $update = array(
                'uid' => $pid,
                'year' => $temp[0],
                'month' => $temp[1],
                'money' => $money,
                'ctime' => time(),

            );
            $insertiD = $model->add($update);

            if ($insertiD) {

                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        $this->assign('userinfo', $userinfo);

        //设置全局信息
        $title = "添加缴费记录";
        $this->assign('title', $title);

        $this->assign('pid', $pid);
        return view('addPartymoneyData');

    }

    public function addData()
    {

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {
            $uname = trim(input("request.uname"));//auth
            $nickname = trim(input("request.nickname"));//auth
            $pwd = trim(input("request.pwd"));//auth
            $first_depid = trim(input("request.first_depid"));//auth
            $depid = trim(input("request.depid"));//auth
            $group = trim(input("request.group"));//auth
            $phone = trim(input("request.phone"));//auth
            $head = trim(input("request.head"));//auth


            $sex = trim(input("request.sex"));//auth
            $cid = trim(input("request.cid"));//auth
            $bday = trim(input("request.bday"));//auth
            $height = trim(input("request.height"));//auth
            $weight = trim(input("request.weight"));//auth
            $alipay_name = trim(input("request.alipay_name"));//auth
            $alipay_account = trim(input("request.alipay_account"));//auth
            $vip = trim(input("request.vip"));//auth


            if (empty($depid)) {
                $depid = $first_depid;
            }
            if (empty($uname)) {

                $return = ['err' => 3, 'msg' => '对不起登录名称不能为空'];
                return json($return);
            }
            $oldGroup = $this->_model->getDataForWhere(array(
                'uname' => $uname,
            ));
            if (!empty($oldGroup)) {
                $return = ['err' => 3, 'msg' => '对不起账号已经存在'];
                return json($return);
            }
            $pwd = userPWD($pwd);
            $insertData = array(
                'uname' => $uname,
                'nickname' => $nickname,
                'pwd' => $pwd,
                'first_depid' => $first_depid,
                'depid' => $depid,
                'group' => $group,
                'phone' => $phone,
                'head' => $head,
                'sex' => $sex,
                'cid' => $cid,
                'bday' => $bday,
                'height' => $height,
                'alipay_name' => $alipay_name,
                'weight' => $weight,
                'alipay_account' => $alipay_account,
                'vip' => $vip,
                'ctime' => date("Y-m-d H:i:s"),
            );


            $res = $this->_model->add($insertData);

            if ($res) {
                addUserSystemGroup($res, $group);
                //操作日志记录
                //$userInfo =$this->_model->getID($id);
                $action = "新增用户[" . $insertData['uname'] . "][" . $insertData['nickname'] . "][id:" + $res + "]";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 4,
                ]);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //查询部门
        $depModel = new \app\admin\model\Dep();

        $depid = $this->LoginUserInfo['UserInfo']['first_depid'];
        $group = $this->LoginUserInfo['UserInfo']['group'];
        $depwhere = array(
            'father' => 0
        );
        if ($group == 2) {
            $depwhere['id'] = $depid;
        }

        $FirstDepList = $depModel->getDataForWheres($depwhere);//查询一级部门
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $FirstDepList[0]['id']
        ));//查询二级部门

        $tempFirstarr = array();

        foreach ($SecondDepList as $k => $v) {
            $SecondDepList[$v['id']] = $v;
        }
        foreach ($FirstDepList as $k => $v) {
            $tempFirstarr[$v['id']] = $v;
        }
        //print_r($FirstDepList);

        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $tempFirstarr);


        if ($group == 2) {
            $groupModel = new \app\admin\model\Group();
            $groupList = $groupModel->getDataForWheres(array('id' => array('gt', 2)));

        } else {
            //查询分组
            $groupModel = new \app\admin\model\Group();
            $groupList = $groupModel->getGroupList();
        }
        $this->assign('groupList', $groupList);
        //查询用户

        //设置全局信息
        $title = "添加用户";
        $this->assign('title', $title);

        return view('addData');

    }


    public function resetPwd()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        $userInfo = $this->_model->getID($id);
        if ($sys_opt) {
            $pwd = trim(input("request.pwd"));//auth
            $pwd = userPWD($pwd);
            $w = array(
                'id' => $id
            );
            $update = array(
                'pwd' => $pwd,

            );
            $res = $this->_model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {
                //操作日志记录
                //$userInfo =$this->_model->getID($id);
                $action = "充值密码[" . $userInfo['uname'] . "][" . $userInfo['nickname'] . "][id:" + $id + "]";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 4,
                ]);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }


        //设置全局信息
        $title = "重置密码";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('resetPwd');

    }

    public function updateMapFile()
    {
        $pic = trim(input("request.pic"));//auth
        $model = new \app\admin\model\Mapfiles();
        if (empty($pic)) {
            $return = ['err' => 3, 'msg' => '操作失败,文件为空'];
            return json($return);
        }
        $w = array('id' => 1);
        $update = array('url' => $pic);
        $res = $model->updateDataForWhere($update, $w);

        if ($res || ($res === 0)) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }

    }

    public function editData()
    {

        $id = trim(input("request.id"));//auth
        $sys_opt = trim(input("request.sys_opt"));//auth
        //查询用户
        $info = $this->_model->getDataForWhere(array('id' => $id));

        if ($sys_opt) {
            $nickname = trim(input("request.nickname"));//auth
            //$group = trim(input("request.group"));//auth
            $first_depid = trim(input("request.first_depid"));//auth
            $depid = trim(input("request.depid"));//auth
            $phone = trim(input("request.phone"));//auth
            $head = trim(input("request.head"));//auth
            $sex = trim(input("request.sex"));//auth
            $cid = trim(input("request.cid"));//auth
            $bday = trim(input("request.bday"));//auth
            $height = trim(input("request.height"));//auth
            $weight = trim(input("request.weight"));//auth
            $alipay_name = trim(input("request.alipay_name"));//auth
            $alipay_account = trim(input("request.alipay_account"));//auth
            $vip = trim(input("request.vip"));//auth
            if (empty($depid)) {
                $depid = $first_depid;
            }

            $w = array(
                'id' => $id
            );
            $update = array(
                'nickname' => $nickname,
                // 'group' => $group,
                'first_depid' => $first_depid,
                'depid' => $depid,
                'phone' => $phone,
                'head' => $head,
                'sex' => $sex,
                'cid' => $cid,
                'bday' => $bday,
                'vip' => $vip,
                'height' => $height,
                'alipay_name' => $alipay_name,
                'weight' => $weight,
                'alipay_account' => $alipay_account,
            );
            $res = $this->_model->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {
                //操作日志记录
                //$userInfo =$this->_model->getID($id);
                $action = "修改用户[" . $info['uname'] . "][" . $info['nickname'] . "][id:" + $id + "]";

                $this->recordSystemLog([
                    'user' => $this->LoginUserInfo['UserInfo']['id'],
                    'time' => date("Y-m-d H:i:s"),
                    'action' => $action,
                    'type' => 4,
                ]);
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        $this->assign('info', $info);
        //查询部门
        $depModel = new \app\admin\model\Dep();

        $depid = $this->LoginUserInfo['UserInfo']['first_depid'];
        $group = $this->LoginUserInfo['UserInfo']['group'];
        $depwhere = array(
            'father' => 0
        );
        if ($group == 2) {
            $depwhere['id'] = $depid;
        }
        $FirstDepList = $depModel->getDataForWheres($depwhere);//查询一级部门
        $selectSecondID = $FirstDepList[0]['id'];
        if ($info['first_depid']) {
            $selectSecondID = $info['first_depid'];
        }
        $SecondDepList = $depModel->getDataForWheres(array(
            'father' => $selectSecondID
        ));//查询二级部门
        $this->assign('SecondDepList', $SecondDepList);
        $this->assign('FirstDepList', $FirstDepList);


        if ($group == 2) {
            $groupModel = new \app\admin\model\Group();
            $groupList = $groupModel->getDataForWheres(array('id' => array('gt', 2)));

        } else {
            //查询分组
            $groupModel = new \app\admin\model\Group();
            $groupList = $groupModel->getGroupList();
        }

        $this->assign('groupList', $groupList);


        //设置全局信息
        $title = "编辑用户信息";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('editData');

    }


    public function peoplemap()
    {


        $depid = $this->LoginUserInfo['UserInfo']['first_depid'];
        $group = $this->LoginUserInfo['UserInfo']['group'];
        $this->assign('depid', $depid);
        $this->assign('group', $group);


        $mapfileList = getAllMapfiles($this->LoginUserInfo['UserInfo']);
        $filemap = trim(input("request.filemap"));
        if (empty($filemap)) {
            $filemap = 0;
        }
        $this->assign('filemap', $filemap);
        $this->assign('mapfileList', $mapfileList);


        //标注
        $biaozhu = trim(input("request.biaozhu"));
        if (empty($biaozhu)) {
            $biaozhu = 0;
        }
        $this->assign('biaozhu', $biaozhu);
        return view('peoplemap');

    }


}